package com.sdvdxl.listener;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.sdvdxl.util.ApplicationData;
import com.sdvdxl.util.GlobalVars;

public class ApplicationListener implements ServletContextListener{

	@Override
	public void contextDestroyed(ServletContextEvent event) {
	}

	@Override
	public void contextInitialized(ServletContextEvent event) {
		ServletContext application = event.getServletContext();
		WebApplicationContext applicationContext =  WebApplicationContextUtils.getWebApplicationContext(application);  
		ApplicationData appData = (ApplicationData) applicationContext.getBean("applicationData"); 
		//加载全局数据
		GlobalVars.getInstance().setContext(application);
		GlobalVars.getInstance().init();
		
		//加载分类和标签
		appData.setContext(application);
		appData.init();
	}

}
